function _toConsumableArray(a) {
  if (Array.isArray(a)) {
    for (var t = 0, e = Array(a.length); t < a.length; t++) e[t] = a[t];
    return e;
  }
  return Array.from(a);
}

var app = getApp();

Page({
  data: {
    nav_index: 0,
    page: 2,
    more: !0,
    bg2: "",
    mylevel: 0
  },
  onLoad: function (a) {

    var e = this;
    var userInfo = wx.getStorageSync("userInfo");
    // app.getGlobalInfo(function(a) {
    //     var t = a.bg2 ? a.bg2 : "../../image/bg2.jpg";
    //     console.log("t",t);
    //     e.setData({
    //         info: a,
    //         bg2: t
    //     });
    // });

    let db = wx.cloud.database()

    db.collection('user_info').where({
      pass: db.command.gte(userInfo.wxInfo.pass)

    }).get({
      success: res => {
        console.log("====", res.data.length);
        e.setData({
          mylevel: res.data.length + 1
          //     rank_friend: res.data,
          //     user: userInfo.wxInfo
        });

      }
    });

    db.collection('user_info').orderBy('pass', 'desc')
      .limit(10)
      .get({
        success: res => {
          console.log("====", res);
          e.setData({
            rank_friend: res.data,
            user: userInfo.wxInfo
          });
          // let feeds = this.data.feeds;
          // for (let i = 0; i < res.data.length; i++) {
          //   feeds.push(res.data[i]);
          // }
          // this.setData({
          //   feeds: feeds,
          //   page: page + 1
          // })
        },
        fail: err => {
          console.log('[数据库] [查询记录] 失败：');
        }
      });


    // wx.cloud.callContainer({

    //   config: {
    //     env: 'prod-1gf9s5bjbb49e183', // 微信云托管的环境ID
    //   },
    //   path: 'entry/wxapp/rank', // 填入业务自定义路径和参数，根目录，就是 / 
    //   method: 'POST', // 按照自己的业务开发，选择对应的方法
    //   header: {
    //     'X-WX-SERVICE': 'springboot', // xxx中填入服务名称（微信云托管 - 服务管理 - 服务列表 - 服务名称）
    //     "content-type": "application/x-www-form-urlencoded"
    //   },
    //   data: {
    // 		'openid': user.openid
    // 	},
    //   success(res) {
    //   e.setData({
    //       rank_friend: res.data.rank_friend,
    //       user: res.data.user
    //   });
    //    }
    //   // dataType:'text', // 默认不填是以 JSON 形式解析返回结果，若不想让 SDK 自己解析，可以填text
    // });


  },
  loadMore: function () {
    var e = this;
    e.data.more && app.call({
      path: "entry/wxapp/rank",
      method: "POST",
      data: {
        page: e.data.page,
        m: "yige_fkscdh"
      },
      success: function (a) {
        console.log(a.data.data);
        var t = a.data.data;
        0 == t.rank_word.length ? (wx.showToast({
          title: "已经到底了~",
          icon: "success",
          duration: 2e3
        }), e.setData({
          more: !1
        })) : e.setData({
          rank_word: [].concat(_toConsumableArray(e.data.rank_word), _toConsumableArray(t.rank_word)),
          page: ++e.data.page
        });
      }
    });
  },
  changeNav: function (a) {
    var t = a.currentTarget.dataset.index;
    this.setData({
      nav_index: t
    });
  },
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {},
  onShareAppMessage: function () {
    var a = this;
    return wx.updateShareMenu({
      withShareTicket: !0,
      success: function (a) {}
    }), {
      title: a.data.info.share_text ? a.data.info.share_text : a.data.info.name,
      path: "/pages/index/index?friendid=" + app.globalData.userid,
      success: function (a) {
        console.log("/pages/index/index?friendid=" + app.globalData.userid);
      }
    };
  }
});